import jsonimport requestsimport pandas as pdimport datetimeimport timeimport pytzimport numpy as npimport matplotlib.pyplot as pltfrom pandas.plotting import register_matplotlib_convertersimport urllibimport dateutil.parser from datetime import datetimefrom pytz import timezoneimport os!pip install foliumimport foliumfrom folium.plugins import TimestampedGeoJsonimport seaborn as snsfrom folium import pluginsdata=pd.read_csv("Project3PlateTectonics.csv")data.shapetime=data.time magnitude=data.mag latitude=data.latitudelongitude=data.longitudetime1=pd.to_datetime(time, format='%Y-%m-%dT%H:%M:%S.%fZ')plt.scatter(time1,magnitude)plt.ylabel('Magnitude')plt.xlabel('Time')plt.title('Eartquake magnitude 2010-2020')print("minimum", min(magnitude))print("maximum", max(magnitude))avg = sum(magnitude)/len(magnitude)print("average", avg)# Earthquake locations (lat and lon) on a map with magnitudem=folium.Map(location=[47.7589 , -130 ], zoom_start=5)for index, row in data.iterrows(): folium.CircleMarker([row['latitude'], row['longitude']], radius= [row['mag']], popup=print(row['mag']), #fill_color="#3db7e4", # divvy color ).add_to(m)coordinates=[(40.5, -128.040335),(40.5, -124)],[(45, -130.040335),(43, -126)]aline=folium.PolyLine(locations=coordinates,weight=2,color = 'red')m.add_child(aline)mx
for index, row in data.iterrows(): folium.CircleMarker([row['latitude'], row['longitude']], radius='magnitude', #popup=row['name'], fill_color="#3db7e4", # divvy color ).add_to(m)mapname.save(Filename.html)# EXTRA CREDIT (Interactive Map with scroll to move)df=datadef create_geojson_features(df): print('> Creating GeoJSON features...') features = [] for _, row in data.iterrows(): feature = { 'type': 'Feature', 'geometry': { 'type':'Point', 'coordinates':[row['longitude'],row['latitude']] }, 'properties': { 'time': row['time'], 'style': {'color' :'red'}, 'icon': 'circle', 'iconstyle':{ # 'fillColor': row['color'], 'fillOpacity': 0.8, 'stroke': 'true', 'radius': row['mag'] } } } features.append(feature) return featuresxxxxxxxxxxdef make_map(features): print('> Making map...') coords_US=[50.5039, -130] pollution_map = folium.Map(location=coords_US, control_scale=True, zoom_start=5) TimestampedGeoJson( {'type': 'FeatureCollection', 'features': features} , period='P1M' , add_last_point=True , auto_play=False , loop=False , max_speed=1 , loop_button=True , date_options='YYYY/MM' , time_slider_drag_update=True ).add_to(pollution_map) print('> Done.') return pollution_mapdef plot_pollutant(df): #print('Mapping {} pollution in Belgium in 2013-2015'.format(pollutants[pollutant_ID]['name'])) #df = load_data(pollutant_ID) # df = clean_data(df) #df = prepare_data(df, pollutant_ID) features = create_geojson_features(df) return make_map(features), dfxxxxxxxxxxpollution_map, df = plot_pollutant(df)pollution_mapxxxxxxxxxx BBox = ((data.longitude.min(), data.longitude.max(), data.latitude.min(), data.latitude.max()))print(BBox)xxxxxxxxxxxxxxxxxxxxdata=pd.read_csv("Project3Ocean_2015data.csv")data.shape#T_raw=data.loc[:,'time']#Time = []#new_format= "%Y-%m-%d %H:%M:%S"#for i in range (len(T_raw)):# datecheck=datetime.strptime(T_raw[i],"%Y-%m-%dT%H:%M:%S.%fz").replace(microsecond=0)# datecheck.strftime(new_format)# Time.append(datecheck)time1=data.time1 mag1=data.mag1 latitude=data.latitudelongitude=data.longitudem1=folium.Map(location=[47.7589 , -130 ], zoom_start=3)for index, row in data.iterrows(): folium.CircleMarker([row['latitude'], row['longitude']], radius= row['mag1'], #popup=print(row['mag']), #fill_color="#3db7e4", # divvy color ).add_to(m1) xxxxxxxxxxm1xxxxxxxxxxtime2=pd.to_datetime(time2, format='%Y-%m-%dT%H:%M:%S.%fZ')plt.scatter(time2,magnitudee)plt.xticks(rotation=30)plt.ylabel('Magnitude')plt.xlabel('Time')plt.title('Eartquake magnitude on April 2015')xxxxxxxxxxdata=pd.read_csv("Divergrent_and_Boundarydata.csv")data.shape#T_raw=data.loc[:,'time']#Time = []#new_format= "%Y-%m-%d %H:%M:%S"#for i in range (len(T_raw)):# datecheck=pd.to_datetime(time2, format='%Y-%m-%dT%H)# Time.append(datecheck)time3=[]for i in range (len(data)): time3.append(dateutil.parser.isoparse(data['time3'][i]))#time2=data.time1 mag3=data.mag3 latitude=data.latitudelongitude=data.longitudem1=folium.Map(location=[47.7589 , -130 ], zoom_start=5)for index, row in data.iterrows(): folium.CircleMarker([row['latitude'], row['longitude']], radius= row['mag3'], #popup=print(row['mag']), #fill_color="#3db7e4", # divvy color ).add_to(m1) coordinates=[(40.5, -128.040335),(40.5, -124)],[(45, -130.040335),(43, -126)] aline=folium.PolyLine(locations=coordinates,weight=2,color = 'red') m1.add_child(aline)xxxxxxxxxxm1xxxxxxxxxxplt.scatter(time3,mag3)plt.xticks(rotation=30)plt.ylabel('Magnitude')plt.xlabel('Time (yrs)')plt.title('Earth quakes from 2010-2020 (Red line Marks Transform Boundary)')xxxxxxxxxxdata=pd.read_csv("Divergrent_and_Boundarydata.csv")data.shape#T_raw=data.loc[:,'time']#Time = []#new_format= "%Y-%m-%d %H:%M:%S"#for i in range (len(T_raw)):# datecheck=pd.to_datetime(time2, format='%Y-%m-%dT%H)# Time.append(datecheck)time3=[]for i in range (len(data)): time3.append(dateutil.parser.isoparse(data['time3'][i]))#time2=data.time1 mag3=data.mag3 latitude=data.latitudelongitude=data.longitudem1=folium.Map(location=[45.7589 , -128 ], zoom_start=5)for index, row in data.iterrows(): folium.CircleMarker([row['latitude'], row['longitude']], radius= row['mag3'], #popup=print(row['mag']), #fill_color="#3db7e4", # divvy color ).add_to(m1) coordinates=[(40.5, -127.040335),(42.5, -126.5)],[(45, -130.040335),(49, -128)] aline=folium.PolyLine(locations=coordinates,weight=2,color = 'green') m1.add_child(aline)xxxxxxxxxxm1xxxxxxxxxxplt.scatter(time3,mag3)plt.xticks(rotation=30)plt.ylabel('Magnitude')plt.xlabel('Time (yrs)')plt.title('Earth quakes from 2010-2020 (Red line Marks Subduction Boundary)')xxxxxxxxxx